﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Zzva.Common
{
    public struct TCodeComp
    {
        public string FullCode;
        public string Dse;
        public float DispNumeric;
        public string  DispString;
        public string Order;
        public int DopIsp;

    }

    public class  TConvertCodeComp
    {						

        private const string mvarSmbOrder   = "/";
        private const string mvarSmbDopIsp = "/";
        private const string mvarSmbDisp = "-";
        private const string mvarDispNull = "00";

 

        public static TCodeComp GetCodeComp(string pFullObozn)
        {
            try
            {
                TCodeComp lCodeComp;
                string lDseDisp;
                string lOrderDopIsp;
                string lDse;
                string lDisp;
                string lOrder;
                string  lDopIsp;

                


                pFullObozn.TrimEnd(); 

                int IndexSmbOrder = pFullObozn.IndexOf(mvarSmbOrder);
  
                if (IndexSmbOrder == -1) //Это не заказаная 
                {
                    lDseDisp = pFullObozn;
                    lOrder = "";
                    lDopIsp = "0";

                }  
                else //это заказная
                {
                    lDseDisp = pFullObozn.Substring(0, IndexSmbOrder);
                    lOrderDopIsp = pFullObozn.Substring(IndexSmbOrder + 1);

                    int IndexSmbDopIsp = lOrderDopIsp.IndexOf(mvarSmbDopIsp);
                    if (IndexSmbDopIsp == -1){throw (new CommonException("Не найден DopIsp в коде " + pFullObozn));}
                    lOrder = lOrderDopIsp.Substring(0, IndexSmbDopIsp);
                    lDopIsp = lOrderDopIsp.Substring(IndexSmbDopIsp + 1);
                }



                int IndexSmbDisp = lDseDisp.IndexOf(mvarSmbDisp);
                if (IndexSmbDisp == -1) //это нулевое исполнение
                {
                    lDse = lDseDisp;
                    lDisp = mvarDispNull;
                }
                else 
                {
                    lDse = lDseDisp.Substring(0, IndexSmbDisp);
                    lDisp = lDseDisp.Substring(IndexSmbDisp + 1);

                }



                lCodeComp = new TCodeComp();
                lCodeComp.FullCode = pFullObozn;
                lCodeComp.Dse = lDse;
                lCodeComp.DispString = lDisp;
                lCodeComp.DispNumeric = float.Parse(lDisp);
                lCodeComp.Order = lOrder;
                lCodeComp.DopIsp = int.Parse(lDopIsp); 





                return lCodeComp; 
            }

            catch (Exception e) { throw e; }
            finally { }
        }




        public static TCodeComp GetCodeComp(string Dse,string Disp,
                                         string Order,int DopIsp)
        {
            try
            {
                TCodeComp lCodeComp;
                lCodeComp = new TCodeComp();




                return lCodeComp;
            }

            catch (Exception e) { throw e; }
            finally { }
        }

        public static TCodeComp GetCodeComp(string Dse, string Order, int DopIsp)
        {
            try
            {
                TCodeComp lCodeComp;
                lCodeComp = new TCodeComp();




                return lCodeComp;
            }

            catch (Exception e) { throw e; }
            finally { }
        }



        public static TCodeComp GetCodeComp(string Dse, float  Disp,
                                         string Order, int DopIsp)
        {
            try
            {
                TCodeComp lCodeComp;
                lCodeComp = new TCodeComp();




                return lCodeComp;
            }

            catch (Exception e) { throw e; }
            finally { }
        }




    }

}
